Assignemnt #39 and Thirty-sixth Program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: Thirty-sixth Program
///File name: ThirsiProg.java
///Date Finished:10/6/2015
import java.util.Scanner;
public class ThirsiProg
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int answer, overall=0;
String anything;
System.out.print( "Are you ready for a quiz? " );
anything = keyboard.next();
System.out.println( "Okay, here it comes!" );
System.out.println( "Q1: What is the capital of Alaska?" );
System.out.println( "1: Melbourne" );
System.out.println( "2: Anchorage" );
System.out.println( "3: Juneau" );
System.out.println();
System.out.print( "> " );
answer = keyboard.nextInt();
if(answer == 1)
{
System.out.println( "Sorry, that's wrong." );
}
if(answer == 2)
{
System.out.println( "Sorry, that's wrong." );
}
if(answer == 3)
{
System.out.println( "That's right!" );
overall++;
}
System.out.println( "Q2: Can you store the value cat in a variable of type int?" );
System.out.println( "1: yes" );
System.out.println( "2: no" );
System.out.println();
System.out.print( "> " );
answer = keyboard.nextInt();
if(answer == 1)
{
System.out.println( "Sorry, that's wrong." );
}
if(answer == 2)
{
System.out.println( "Correct! cat is a string variable." );
overall++;
}
System.out.println( "Q3: What is the result of 9+6/3?" );
System.out.println( "1: 5" );
System.out.println( "2: 11" );
System.out.println( "3: 15/3" );
System.out.println();
System.out.print( ">" );
answer = keyboard.nextInt();
if(answer == 1)
{
System.out.println( "Sorry, that's wrong." );
}
if(answer == 2)
{
System.out.println( "That's correct!" );
overall++;
}
if(answer == 3)
{
System.out.println( "Sorry, that's wrong." );
}
System.out.println( "Overall, you got " + overall + " out of 3 correct." );
System.out.println( "Thanks for playing!" );
}
}
Picture of the output